﻿Imports System.Collections.Specialized
Imports System.IO
Imports System.Globalization
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports System.Collections.ObjectModel
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling

    Class Application

    'Application-level events, such as Startup, Exit, and DispatcherUnhandledException
    'can be handled in this file.

    'The name of the application folder.  This folder is used to save the files 
    'for this application such as the photos, stories and family data.
    <System.STAThreadAttribute()> _
Public Shared Sub Main()
        Dim app As New Application()
        app.Run()
    End Sub



    Protected Overrides Sub OnStartup(ByVal e As System.Windows.StartupEventArgs)
        MyBase.OnStartup(e)
#If DEBUG Then
        RunInDebugMode()
#Else
                RunInReleaseMode()
#End If
        Me.ShutdownMode = ShutdownMode.OnMainWindowClose
    End Sub

    Private Shared Sub RunInDebugMode()
        Dim bootstrapper As New TFSStickyBuddyBootstrapper()
        bootstrapper.Run()
    End Sub

    Private Shared Sub RunInReleaseMode()
        AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomainUnhandledException
        Try
            Dim bootstrapper As New TFSStickyBuddyBootstrapper()
            bootstrapper.Run()
        Catch ex As Exception
            HandleException(ex)
        End Try

    End Sub

    Private Shared Sub AppDomainUnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
        HandleException(e.ExceptionObject)
    End Sub

    Private Shared Sub HandleException(ByVal ex As Exception)
        If ex Is Nothing Then
            Return
        End If
        ExceptionPolicy.HandleException(ex, "Default Policy")
        MessageBox.Show(My.Resources.UnhandledException)
        Environment.Exit(1)
    End Sub



    End Class
